﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Xml.Linq;
using System.Collections.Generic;

using YouHP.Model;
using YouHP.BLL;

namespace web.admin
{
    public partial class DiseaseType : System.Web.UI.Page
    {
        private DiseaseBLL diseaseBll = DiseaseBLL.Instance;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }

        private void bind()
        {
            List<DiseaseTypeInfo> list = null;

            try
            {
                //根据关键字匹配疾病名称
                list = diseaseBll.GetDiseaseTypeList(0);    /*获得一级分类疾病类型*/
            }
            catch(Exception ex)
            {
                throw ex;
            }

            this.diseaseTypeList.DataSource = list;
            this.diseaseTypeList.DataBind();
        }

        protected void DeleteBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int[] idList = new int[this.diseaseTypeList.Rows.Count];

                for (int rowIndex = 0; rowIndex < this.diseaseTypeList.Rows.Count; rowIndex++)
                {
                    bool ischeck = ((CheckBox)this.diseaseTypeList.Rows[rowIndex].Cells[0].FindControl("chk")).Checked;
                    if (ischeck)
                    {
                        idList[rowIndex] = Convert.ToInt32(this.diseaseTypeList.DataKeys[rowIndex].Value);
                    }
                }

                diseaseBll.DelDiseaseType(idList);
            }
            catch(Exception ex) { 
                /*抛出异常，因为可能该疾病类型对应的疾病还没有先被删除掉*/
                throw ex;
            }

            bind();
        }

    }
}
